package edu.hawaii.myisern.model;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;

/**
 * Tests the MyCollaboration record class.
 * 
 * @author Randy Cox
 * 
 */
public class TestMyCollaboration {

  /**
   * Test constructor, make sure fields are initialized.
   */
  @Test
  public void testMyCollaboration() {
    MyCollaboration collaboration = new MyCollaboration();

    // Check init.
    assertNotNull("Check non-null ID.", collaboration.getId());
    assertNotNull("Check non-null name.", collaboration.getName());
    assertNotNull("Check non-null desc.", collaboration.getDescription());
    assertNotNull("Check non-null contact.", collaboration.getOrganizations());
    assertNotNull("Check non-null researchers.", collaboration.getYears());
    assertNotNull("Check non-null country.", collaboration.getTypes());
    assertNotNull("Check non-null keywords.", collaboration.getOutcomes());

    // Set up test strings.
    String id = ("COLLABORATION_NAME");
    String name = "collaboration name ";
    String desc = "Desc";
    String[] organizations = { "Organization1", "Organization2", "Organization3" };
    String[] years = { "2000", "2001", "2002" };
    String[] types = { "Type1", "Type2", "Type3" };
    String[] outcomes = { "Outcome1", "Outcome2", "Outcome3" };
    List<String> orgList = new ArrayList<String>();
    orgList.add("OrgA");
    orgList.add("OrgB");
    orgList.add("OrgC");
    List<String> yearList = new ArrayList<String>();
    yearList.add("2003");
    yearList.add("2004");
    yearList.add("2005");
    List<String> typeList = new ArrayList<String>();
    typeList.add("TypeA");
    typeList.add("TypeB");
    typeList.add("TypeC");
    List<String> outcomeList = new ArrayList<String>();
    outcomeList.add("OutcomeA");
    outcomeList.add("OutcomeB");
    outcomeList.add("OutcomeC");

    // Set up record vars.
    collaboration.setName(name);
    collaboration.setDescription(desc);
    collaboration.setOrganizations(orgList);
    collaboration.addOrganization(organizations[0]);
    collaboration.addOrganization(organizations[1]);
    collaboration.addOrganization(organizations[2]);
    collaboration.setYears(yearList);
    collaboration.addYear(years[0]);
    collaboration.addYear(years[1]);
    collaboration.addYear(years[2]);
    collaboration.setTypes(typeList);
    collaboration.addType(types[0]);
    collaboration.addType(types[1]);
    collaboration.addType(types[2]);
    collaboration.setOutcomes(outcomeList);
    collaboration.addOutcome(outcomes[0]);
    collaboration.addOutcome(outcomes[1]);
    collaboration.addOutcome(outcomes[2]);

    // Check vars.
    assertEquals("Check ID.", id, collaboration.getId());
    assertEquals("Check name.", name, collaboration.getName());
    assertEquals("Check desc.", desc, collaboration.getDescription());
    assertEquals("Check orgA.", orgList.get(0), collaboration.getOrganizations().get(0));
    assertEquals("Check orgB.", orgList.get(1), collaboration.getOrganizations().get(1));
    assertEquals("Check orgC.", orgList.get(2), collaboration.getOrganizations().get(2));
    assertEquals("Check org1.", organizations[0], collaboration.getOrganizations().get(3));
    assertEquals("Check org2.", organizations[1], collaboration.getOrganizations().get(4));
    assertEquals("Check org3.", organizations[2], collaboration.getOrganizations().get(5));
    assertEquals("Check yearA.", yearList.get(0), collaboration.getYears().get(0));
    assertEquals("Check yearB.", yearList.get(1), collaboration.getYears().get(1));
    assertEquals("Check yearC.", yearList.get(2), collaboration.getYears().get(2));
    assertEquals("Check year1.", years[0], collaboration.getYears().get(3));
    assertEquals("Check year2.", years[1], collaboration.getYears().get(4));
    assertEquals("Check year3.", years[2], collaboration.getYears().get(5));
    assertEquals("Check typeA.", typeList.get(0), collaboration.getTypes().get(0));
    assertEquals("Check typeB.", typeList.get(1), collaboration.getTypes().get(1));
    assertEquals("Check typeC.", typeList.get(2), collaboration.getTypes().get(2));
    assertEquals("Check type1.", types[0], collaboration.getTypes().get(3));
    assertEquals("Check type2.", types[1], collaboration.getTypes().get(4));
    assertEquals("Check type3.", types[2], collaboration.getTypes().get(5));
    assertEquals("Check outcomeA.", outcomeList.get(0), collaboration.getOutcomes().get(0));
    assertEquals("Check outcomeB.", outcomeList.get(1), collaboration.getOutcomes().get(1));
    assertEquals("Check outcomeC.", outcomeList.get(2), collaboration.getOutcomes().get(2));
    assertEquals("Check outcome1.", outcomes[0], collaboration.getOutcomes().get(3));
    assertEquals("Check outcome2.", outcomes[1], collaboration.getOutcomes().get(4));
    assertEquals("Check outcome3.", outcomes[2], collaboration.getOutcomes().get(5));

    // Check toString().
    String comma = ", ";
    String expected = id + comma + name + comma + desc;
    assertEquals("Check toString.", expected, collaboration.toString());

    // Check validate.
    assertTrue("Check validate.", collaboration.validate());
    collaboration.setName("");
    assertFalse("Check bad validate.", collaboration.validate());
  }
}
